/////////////////////////////////////////////////////////////////////////////////////////////////////
//	File	:	"CObjectManager.cpp"
//
//	Author	:	Travis Setz (TS)
//
//	Purpose	:	The CPP file for the object manager to contain and manage all of the game objects.
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "CObjectManager.h"
#include "CBase.h"

CObjectManager::CObjectManager(void)
{
}

CObjectManager::~CObjectManager(void)
{
}

void CObjectManager::UpdateObjects(float fElapsedTime)
{
	vector<CBase*>::iterator iter = m_vObjects.begin();

	while(iter != m_vObjects.end())
	{
		(*iter)->Update(fElapsedTime);
		iter++;
	}
}

void CObjectManager::RenderObjects(void)
{
	for (unsigned int i=0; i < m_vObjects.size(); i++)
		m_vObjects[i]->Render();
}

void CObjectManager::AddObject(CBase* pObject)
{
	if (pObject == NULL)
		return;

	m_vObjects.push_back(pObject);
	pObject->AddRef();
}

void CObjectManager::RemoveObject(CBase* pObject)
{
	if (pObject == NULL)
		return;

	for (vector<CBase*>::iterator iter = m_vObjects.begin(); iter != m_vObjects.end(); iter++)
	{
		if ((*iter) == pObject)
		{
			(*iter)->Release();
			iter = m_vObjects.erase(iter);
			break;
		}
	}
}

void CObjectManager::RemoveAllObjects(void)
{
	for (unsigned int i=0; i < m_vObjects.size(); i++)
	{
		m_vObjects[i]->Release();
	}
	m_vObjects.clear();
}

void CObjectManager::CheckCollisions(void)
{
	for(unsigned int i=0; i < m_vObjects.size(); i++)
	{
		for(unsigned int j=0; j < m_vObjects.size(); j++)
		{
			if(m_vObjects[i] != m_vObjects[j])
			{
				if(m_vObjects[i]->CheckCollision(m_vObjects[j]))
					break;
			}
		}
	}
}